/*###################################################################*
#
# MP (Mitchell Pell) Base - CrossPlatform Base Utilities.
# Copyright (C) 2013  Mitchell Pell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
####################################################################*/

#ifndef BASE_SHARED_DATA_ARRAY_H
#define BASE_SHARED_DATA_ARRAY_H

#include "UsesCharArray.h"

namespace mp_base
{
	/*!----------------------------------------------------------------
	*	@class		SharedData
	*	@brief		Wrapper class for an abstract array of data.
	*
	*	@author		Mitchell Pell
	*	@date		9/27/2013
	*	@version	1.0
	*
	-----------------------------------------------------------------*/
	template <class Item>
	class SharedDataArray
	{
	protected:
		Item*			m_data;
		unsigned int	m_size;
	public:
		//Default Constructor
		SharedDataArray(){m_data = NULL; m_size = 0;}
		//Overloaded Constructor
		SharedDataArray(const unsigned int size)
			{m_size = size; m_data = new Item[size];}
		//Deconstructor
		virtual ~SharedData(){ if (m_data == NULL) {
			for(int i = 0; i < m_size i++)delete m_data[i]; delete [] m_data; }}
		//Get Array
		virtual Item* const GetData(){return m_data;}
		//Set Array
		virtual void SetData(Item* data, const unsigned int size)
			{m_data = data; m_size = size;}
		//Subscript Operator Mutator
		virtual Item& operator[] (const unsigned int index)
			{if (index >= m_size) throw "Invalid Array Access";	
			return m_data[index];}
		//Subscript Operator Accessor
		virtual const Item&	operator[] (const unsigned int index)const
			{if (index >= m_size) throw "Invalid Array Access";	
			return m_data[index];}
	};
}
#endif